﻿using Newtonsoft.Json.Linq;
using StorageApp.APIS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace StorageApp
{
    /// <summary>
    /// _operator.xaml 的交互逻辑
    /// </summary>
    public partial class _operator : Window
    {
        public string process_id;
        public  _operator(string processId)
        {
            process_id = processId;
            initUserAsync();
            InitializeComponent();
        }
        public string? operator_name;
        public string operator_id = "0";

        public   void initUserAsync()
        {  
                setEmployee(); 
        }
        public async void setEmployee()
        {
            var res = await api.api_employee(process_id);
            if(res["data"]!=null)
                setOperator(employee_g, res["data"]);
        }
       
        private void setOperator(System.Windows.Controls.GroupBox box, JToken? optor)
        {

            box.Content = null;
            var stackPanel = new WrapPanel();
            foreach (var item in optor)
            {
                var button = new System.Windows.Controls.Button();
                button.Width = 120;
                button.Height = 100;
                button.Margin = new Thickness(5);
                button.Content = item["name"];
                PropertyHelper.SetProperty(button, item["id"].ToString());
                button.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 0xA9, 0xF6, 0xB8));
              
          
                button.Click += (s, e) => {
                    System.Windows.Controls.Button btn = (System.Windows.Controls.Button)s;
                    string content = btn.Content.ToString();
                    if (content != null)
                    {
                        operator_name=content;
                        operator_id = PropertyHelper.GetProperty(btn);
                    }
                    this.Close();
                };

                stackPanel.Children.Add(button);
            }
            box.Content = stackPanel;
        }
    }
}
